public class IsBalnanceT {


    public boolean isBalanced(TreeNode root) {
        return isBalancedChild(root);
    }

    private boolean isBalancedChild(TreeNode root){
        if(root == null){
            return true;
        }
        int leftHigh = high(root.left);
        int rightHigh = high(root.right);
        return Math.abs(leftHigh - rightHigh) <2 &&
                isBalancedChild(root.left)&&
                isBalancedChild(root.right);
    }


    private int high(TreeNode root){
        if(root == null){
            return 0;
        }
        int left = high(root.left);
        int right = high(root.right);
        return left > right ? left +1 : right +1;
    }
}
